//unsorted.cpp
/********************************************************************************
*																				*
*	Author:			Vanessa Starkey												*
*	Edited By:		Jared Szechy												*
*	Assignment:		Assignment 1												*
*	Class:			CPS-151														*
*	Instructor:		V. Starkley													*
*	Due Date:		August 30													*
*																				*
*	This file implements the functions in for the UnsortedType class.			*
*																				*
********************************************************************************/


#include "unsorted.h"

void UnsortedType::MakeEmpty()
{
    length = 0;
}

UnsortedType::UnsortedType()
{
    length = 0;
}

bool UnsortedType::IsFull() const
{
    return (length == MAX_ITEMS);
}

int UnsortedType::LengthIs() const
{
    return length;
}

bool UnsortedType::RetrieveItem(ItemType& item)
{
	for (int i=0; i<length; i++)
	{
		if (info[i] == item)
		{
			item = info[i];
			return true;
		}
	}
	return false;
}

bool UnsortedType::InsertItem(ItemType item)
{
	//if list is not full, item is stored in next available space.
	if (length == MAX_ITEMS)
		return false;
	else
	{
		info[length] = item;
		length++;
		return true;
	}
}

bool UnsortedType::DeleteItem(ItemType item)
{
	// if item is in list, item is replaced by last item
    for (int i=0; i < length; i++)
	{
		if (info[i] == item)
		{
			info[i] = info[length-1];
			length--;
			return true;
		}
	}
	return false;
}


void UnsortedType::ResetList()
{
    currentPos = 0;
}

bool UnsortedType::GetNextItem(ItemType& item)
{
    if (currentPos == length)
	{
		return false;
	}
	else
	{
		item = info[currentPos];
		currentPos++;
		return true;
	}
}


